package 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	import jiezi.ui.*
	import jiezi.log.*
	import flash.display.Loader;
	import flash.net.URLRequest;

	
	import jiezi.game.jzPlayer;
		
	/**
	 * ...
	 * @author andy
	 */
	public class Main extends Sprite 
	{
		private var mPlayer:jzPlayer;
		
		public function Main():void 
		{
			this.stage.scaleMode = "noScale";
			this.stage.align = "TL";
			
			var loader:Loader = new Loader();
			var urlReq:URLRequest = new URLRequest("imgs/bg.png");
			loader.load(urlReq);
			this.stage.addChild(loader);

			///////////////////////////////
			
			var ui_mgr:UIManager = UIManager.getSingleton();
			ui_mgr.initialize(this.stage)
			
			var frame:Frame = ui_mgr.createFrame("FRAME", "log_root")
			Logger.getSingleton().initialize(frame)
			frame.setPoint(Region.TOP, Region.BOTTOM, 0, -100)
			frame.setPoint(Region.BOTTOM, Region.BOTTOM)
			frame.setPoint(Region.LEFT, Region.LEFT)
			frame.setPoint(Region.RIGHT, Region.RIGHT)

			mPlayer = new jzPlayer;
			mPlayer.setBody(100);
			mPlayer.setAction(0);
			mPlayer.setDir(2);
			mPlayer.enterScene(this.stage);
			mPlayer.setPosition(1, 1);
			
			////////////////////////////
			var t:Timer = new Timer(1000 / 30)
			t.addEventListener(TimerEvent.TIMER, timerHandler)
			t.start()
			
			this.stage.addEventListener(MouseEvent.MOUSE_DOWN, mousedownHandler);
		}
		
		private function mousedownHandler(event:MouseEvent):void {
			mPlayer.moveTo(event.stageX/32, event.stageY/32);
		}
		
		private function timerHandler(event:Event):void {
			var timer:Timer = Timer(event.target);
			var elapsedT:Number = timer.delay/1000.0;
			mPlayer.update(elapsedT);
		}
	}
	
}